﻿using System.Collections.Generic;
using CivilRegistry.ControlledModel.Repository;

namespace CivilRegistry.ControlledModel
{
    /// <summary>
    /// The unsubscription type.
    /// </summary>
    public partial class UnsubscriptionType
    {
        #region Local Fields

        /// <summary>
        /// Holds the <see cref="UnsubscriptionTypeRepository"/> instance.
        /// </summary>
        static UnsubscriptionTypeRepository repository = new UnsubscriptionTypeRepository();

        #endregion

        #region Methods

        #region Finder Methods

        /// <summary>
        /// Finds the <see cref="UnsubscriptionType"/> by Id.
        /// </summary>
        /// <param name="id">The id of the <see cref="UnsubscriptionType"/>.</param>
        /// <returns>Found <see cref="UnsubscriptionType"/> object, null if not found.</returns>
        public static UnsubscriptionType FindById(int id)
        {
            return repository.FindBy(unsubscriptionType => unsubscriptionType.UnsubscriptionTypeId == id);
        }

        /// <summary>
        /// Finds the <see cref="UnsubscriptionType"/> by name.
        /// </summary>
        /// <param name="name">The <see cref="Unsubscription"/> name.</param>
        /// <returns>Found <see cref="UnsubscriptionType"/> object, null if not found.</returns>
        public static UnsubscriptionType FindByName(string name)
        {
            return repository.FindBy(unsubscriptionType => unsubscriptionType.UnsubscriptionName == name);
        }

        /// <summary>
        /// Finds all <see cref="UnsubscriptionType"/>s.
        /// </summary>
        /// <returns>Found <see cref="UnsubscriptionType"/> objects, empty if none are found.</returns>
        public static List<UnsubscriptionType> FindAll()
        {
            List<UnsubscriptionType> unsubscriptionTypeList = new List<UnsubscriptionType>();
            repository.FindAll().ForEach(unsubscriptionType => unsubscriptionTypeList.Add(unsubscriptionType));
            return unsubscriptionTypeList;
        }

        #endregion

        #endregion

    }
}
